/*****************************************************************************
* Copyright (c) 2014,H.B.
* All rights reserved.
* 
* FileName : DtvManager.java
* Description : define DtvManager
* 
* Version : 0.0.0
* Author : HB   Reviewer : 
* Date : 2014-07-07
* Record : Create
*
* History : 
* (1) Version : 0.0.0
*     Author : HB   Reviewer : 
*     Date : 2014-07-07
*     Record : Create
****************************************************************************/

package hb.dtv;

/**
 * DtvManager manages Tuner and Demux
 * @author H.B.
 */
public class DtvManager
{
	static
	{
		System.loadLibrary("dtvmanager_jni");
	}

	final private int mJniPtr;

	public DtvManager()
	{
		mJniPtr=nativeInit();
	}

	public void Release()
	{
		nativeRelease(mJniPtr);
	}

	public int[] GetTunerCapability()
	{
		return nativeGetTunerCapability(mJniPtr);
	}

	public DtvDemux.Capability GetDemuxCapability()
	{
		return nativeGetDemuxCapability(mJniPtr);
	}

	public DtvTuner GetTuner(int index)
	{
		int tuner = nativeGetTuner(mJniPtr,index);
		return new DtvTuner(tuner);
	}

	public DtvDemux GetDemux(int index)
	{
		int demux = nativeGetDemux(mJniPtr,index);
		return new DtvDemux(demux);
	}

	@Override
	public boolean equals(Object o) 
	{
		 if (this == o) return true;
		 if (!(o instanceof DtvManager)) return false;
		 DtvManager d=(DtvManager)o;
		 if(mJniPtr==d.mJniPtr)return true;
		 return nativeEquals(mJniPtr,d.mJniPtr);
	}

	@Override
	protected void finalize() throws Throwable 
	{
		nativeDestroy(mJniPtr);
		super.finalize();
	}

	private native static int[] nativeGetTunerCapability(int jniPtr);

	private native static DtvDemux.Capability nativeGetDemuxCapability(int jniPtr);

	private native static int nativeGetTuner(int jniPtr,int index);

	private native static int nativeGetDemux(int jniPtr,int index);

	private native static void nativeRelease(int jniPtr);
	
	private native static boolean nativeEquals(int tjniPtr,int ojniPtr);
	
	private native static int nativeInit();
	
	private native static void nativeDestroy(int jniPtr);
}

